Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
simple-validators
Advanced tools
Schema validation functions and error reporting framework
This package provides basic validation functions for building more complex schema validation. It is explicit and verbose with no magic to infer anything from existing types. Rather than throwing validation errors, these functions pass error/warning messages out as options and return undefined
; the consumer may then choose how to handle error reporting.
import fs from 'node:fs';
import {
defined,
incrementOptions,
validateBoolean,
validateEmail,
validateObjectKeys,
validateString,
validationError,
ValidationOptions,
} from 'simple-validators';
// Define typescript type
export type Author = {
id: string;
name?: string;
email?: string;
corresponding?: boolean;
};
// Define validation function for object, which explicitly checks each property
export function validateAuthor(input: any, opts: ValidationOptions) {
const value = validateObjectKeys(
input,
{ required: ['id'], optional: ['name', 'corresponding', 'email'] },
opts,
);
if (value === undefined) return undefined;
const id = validateString(value.id, {
...incrementOptions('id', opts),
regex: '^[a-z][a-zA-Z0-9]{19}$',
});
if (id === undefined) return undefined;
const output: Author = { id };
if (defined(value.name)) {
output.name = validateString(value.name, incrementOptions('name', opts));
}
if (defined(value.email)) {
output.email = validateEmail(value.email, incrementOptions('email', opts));
}
if (defined(value.corresponding)) {
const correspondingOpts = incrementOptions('corresponding', opts);
if (value.corresponding && !defined(value.email)) {
validationError('corresponding author must have email', correspondingOpts);
}
output.corresponding = validateBoolean(value.corresponding, correspondingOpts);
}
return output;
}
// Consume validation function with logging and error handling
export function loadAuthorFromFile(authorFile: string) {
const rawAuthor = JSON.parse(fs.readFileSync(authorFile).toString());
const opts: ValidationOptions = {
file: authorFile,
property: 'author',
messages: {},
errorLogFn: (message: string) => console.log(`Error: ${message}`),
warningLogFn: (message: string) => console.log(`Warning: ${message}`),
};
const author = validateAuthor(rawAuthor, opts);
if (!author || opts.messages.errors?.length) {
throw new Error(`Unable to load author from file ${authorFile}`);
}
return author;
}
FAQs
Schema validation functions and error reporting framework
The npm package simple-validators receives a total of 1,855 weekly downloads. As such, simple-validators popularity was classified as popular.
We found that simple-validators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.